package nl.blindwars.view;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import nl.blindwars.controller.Controller;

public class Window extends JFrame {
	private static final long serialVersionUID = -5290084810690389972L;

	private Controller controller;
	
	public Window(Controller controller) {
		super("Blindwars");
		
		this.controller = controller;
		
		init();
	}
	
	/**
	 * Build the window, sets the menu bar, icon, and makes the whole frame visible.
	 */
	private void init() {
		createMenuBar();
		
		ImageIcon icon = new ImageIcon("icon_nuke.gif");
		setIconImage(icon.getImage());

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(640, 480);
		setLocationRelativeTo(null);
		
		setVisible(true);
	}
	
	/**
	 * Create the menu bar and put it in the window.
	 */
	private void createMenuBar() {
		JMenuBar bar = new JMenuBar();
		
		JMenu menu;
		JMenuItem item;
		
		// File Menu
		menu = new JMenu("File");
		item = new JMenuItem("New game");
		item.addActionListener(controller);
		menu.add(item);

		menu.addSeparator();
		
		item = new JMenuItem("Save");
		item.addActionListener(controller);
		menu.add(item);
		
		item = new JMenuItem("Load");
		item.addActionListener(controller);
		menu.add(item);

		menu.addSeparator();
		
		item = new JMenuItem("Exit");
		item.addActionListener(controller);
		menu.add(item);
		
		bar.add(menu);
		
		// Options Menu
		menu = new JMenu("Options");
		item = new JMenuItem("Difficulty");
		item.addActionListener(controller);
		menu.add(item);	
		
		bar.add(menu);	
		
		// Help Menu
		menu = new JMenu("Help");
		item = new JMenuItem("About");
		item.addActionListener(controller);
		menu.add(item);
		
		bar.add(menu);
		
		setJMenuBar(bar);
	}
}